package com.ctshk.rpc.order.localfun.schedule;

import com.ctshk.common.enums.OrderPaymentStatus;
import com.ctshk.rpc.order.localfun.entity.LocalFunOrder;
import com.ctshk.rpc.order.localfun.mapper.LocalFunOrderMapper;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @Description 最晚付款时间为创建订单后15分钟 定时取消订单
 * @Author wansi <gaylen15527491065@yeah.net>
 * @Date 2021/4/2
 */
public class OrderCancelScheduleTask implements Runnable {

    private Long orderId;
    private LocalFunOrderMapper localFunOrderMapper;

    public OrderCancelScheduleTask(Long orderId, LocalFunOrderMapper localFunOrderMapper) {
        this.orderId = orderId;
        this.localFunOrderMapper = localFunOrderMapper;
    }

    @Override
    public void run() {
        LocalFunOrder localFunOrder = localFunOrderMapper.selectById(orderId);
        if(OrderPaymentStatus.UN_PAYMENT.getCode().equals(localFunOrder.getPaymentStatus())){
            //订单取消
            localFunOrder.setPaymentStatus(OrderPaymentStatus.ALREADY_CANCEL.getCode());
            localFunOrderMapper.updateById(localFunOrder);
        }
    }

}
